package math

import (
	"JVM/Jvmgo/GoToJVM/instructions/base"
	"JVM/Jvmgo/GoToJVM/runtimeData"
)

/*
	这里是进行数学 / 运算
*/

type IDIV struct {
	base.NoOperandsInstruction
}
type LDIV struct {
	base.NoOperandsInstruction
}
type FDIV struct {
	base.NoOperandsInstruction
}
type DDIV struct {
	base.NoOperandsInstruction
}

func (self IDIV) Execute(frame *runtimeData.Frame) {
	stack := frame.OperandStack()
	val2 := stack.PopInt()
	val1 := stack.PopInt()
	if val2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	res := val1 / val2
	stack.PushInt(res)
}
func (self LDIV) Execute(frame *runtimeData.Frame) {
	stack := frame.OperandStack()
	val2 := stack.PopLong()
	val1 := stack.PopLong()
	if val2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	res := val1 / val2
	stack.PushLong(res)
}
func (self FDIV) Execute(frame *runtimeData.Frame) {
	stack := frame.OperandStack()
	val2 := stack.PopFloat()
	val1 := stack.PopFloat()
	if val2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	res := val1 / val2
	stack.PushFloat(res)
}
func (self DDIV) Execute(frame *runtimeData.Frame) {
	stack := frame.OperandStack()
	val2 := stack.PopDouble()
	val1 := stack.PopDouble()
	if val2 == 0 {
		panic("java.lang.ArithmeticException: / by zero")
	}
	res := val1 / val2
	stack.PushDouble(res)
}
